<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function formatWeek(week) {
            switch (week) {
                case 0:
                    return '星期天';
                case 1:
                    return '星期一';
                case 2:
                    return '星期二';
                case 3:
                    return '星期三';
                case 4:
                    return '星期四';
                case 5:
                    return '星期五';
                case 6:
                    return '星期六';
            }
        }
        // 格式化时间当数字小于10，前面补0
        function formatNumber(n) {
            if (n < 10) {
                return '0' + n;
            }
            return n;
        }
        function showTime() {
            var now = new Date();
            var y = now.getFullYear();
            var m = formatNumber(now.getMonth() + 1);
            var d = formatNumber(now.getDate());
            var w = formatWeek(now.getDay()); // 获取星期
            var h = formatNumber(now.getHours());
            var min = formatNumber(now.getMinutes());
            var s = now.getSeconds();
            s = formatNumber(s);

            console.log('%s-%s-%s %s:%s:%s %s', y, m, d, h, min, s, w)
        }
        setInterval(showTime,1000);
    </script>
</body>

</html>